<?php
include("../../classes/bd.php");
include("../../classes/perguntas.php");
$_per 			= new perguntas();
$idpergunta		= $_GET["id"];
$dados			= $_per->pega($idpergunta);
$resposta		= $_per->pegaResposta($idpergunta);
class template{
	var $arquivo;
	var $valor 		= array();
	var $addarquivo = array();
	
	
	function SetValor($chave,$conteudo){	
	$this->valor[$chave]	= $conteudo;
	}

	function FunAddArquivo($tag,$arquivo){	
	$this->addarquivo[$tag] = file_get_contents($arquivo);
	}


	function retornoHtml(){
	
	$html	= file_get_contents($this->arquivo);
	
	foreach ($this->valor as $key => $conteudo) {
	$tagToReplace = "[@$key]";
	$html = str_replace($tagToReplace, $conteudo, $html);
	}
	
	foreach ($this->addarquivo as $key => $conteudo) {
	$TagInclude = "{#$key}";
	$html = str_replace($TagInclude, $conteudo, $html);
	}

	
	
	
	
	
	return $html;
	
	}	
	
	
}



$_class = new template();
$_class->arquivo	= "template/envio.tpl"; 


$_class->SetValor("nome",$dados["nome"]);

	$headers  = "MIME-Version: 1.0 \r\n";
	$headers .= "Content-type: text/html; charset=iso-8859-1\r\n";
	$headers .= "Reply-To: gncbrazil@gmail.com\r\n";
	$headers .= "From: PERGUNTA RESPONDIDA <gncbrazil@gmail.com>" . "\r\n";
	

$html 		= $_class->retornoHtml();
$envio = mail($dados["email"], "PERGUNTA RESPONDIDA | GNC Suplementos",$html , $headers);

?>

<style type="text/css">
<!--
body {
	margin-left: 0px;
	margin-top: 0px;
	margin-right: 0px;
	margin-bottom: 0px;
}
-->
</style>

<link href="../../../style.css" rel="stylesheet" type="text/css">
<form action="cad-resposta.php" method="post">

<input type="hidden" name="id" value="<?=$dados["id"]?>">

<h1 style="color:#333"><?=$dados["pergunta"]?></h1>

<fieldset>
<legend>Responder</legend>
Nome:<br>
<input name="nome" type="text" class="inputGeralGrande" id="nome" value="<?=$resposta['nome']?>">
<br>
<!--<br>
Email:<br>
<input name="email" type="text" class="inputGeralGrande" id="email" value="<?=$resposta['email']?>">
<br>-->
<br>
Resposta:<br>
<textarea name="respostas" cols="60" rows="5" class="inputGeralNormal" id="respostas"><?=$resposta['resposta']?></textarea>
<br>
<br>
<input name="button" type="submit" class="butao-pesquisa" id="button" value="Responder">
</fieldset>


</form>
